package com.fangzhi;

import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.fangzhi.mobel.ProductType;
import com.fangzhi.service.ProductTypeService;
import org.checkerframework.checker.units.qual.A;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.ArrayList;
import java.util.List;

@SpringBootTest
public class PrientProductType {

    @Autowired
    private ProductTypeService productTypeService;

    @Test
    public void start(){
        List<ProductType> list = productTypeService.list(Wrappers.<ProductType>lambdaQuery().eq(ProductType::getLevel, 1));
        List<List<String>> listStr = new ArrayList<>();
        for (ProductType productType : list) {

            List<ProductType> list1 = productTypeService.list(Wrappers.<ProductType>lambdaQuery().eq(ProductType::getParentId, productType.getId()));
            for (ProductType type : list1) {
                List<ProductType> list2 = productTypeService.list(Wrappers.<ProductType>lambdaQuery().eq(ProductType::getParentId, type.getId()));
                for (ProductType productType1 : list2) {
                    List<String> ll = new ArrayList<>();
                    ll.add(productType.getProductName());
                    ll.add(type.getProductName());
                    ll.add(productType1.getProductName());
                    ll.add(String.valueOf(productType1.getPrice() / 100D));
                    listStr.add(ll);
                }
            }
        }
        //通过工具类创建writer
        ExcelWriter writer = ExcelUtil.getWriter("/Users/edy/self/fangzhi/excel/writeTest.xlsx");
        writer.passCurrentRow();
        writer.write(listStr, true);
        writer.close();
    }
}
